{% extends "base.html" %}

{% import "form_macros.html" as form_macros %}

{% macro with_errors(field) %}
    {% if field.errors %}
        <tr class="form_row form_row_error">
    {% else %}
        <tr class="form_row">
    {% endif %}

        {% if field.errors %}
            <td class="form_label form_label_error">
        {% else %}
            <td class="form_label">
        {% endif %}
                {% if field.flags.required %}
                    {{ field.label(class="required") }}
                {% else %}
                    {{ field.label() }}
                {% endif %}
            </td>

            <td class="form_field">
            {% if field.errors %}
                {% set css_class = 'has_error ' + kwargs.pop('class', '') %}
                {{ field(class=css_class, **kwargs) }}
                <ul class="errors">{% for error in field.errors %}<li>{{ error|e }}</li>{% endfor %}</ul>
            {% else %}
                {{ field(**kwargs) }}
            {% endif %}
            </td>
    </tr>
{% endmacro %}

{% block content %}
    <form method="POST" action="{{ form_macros.form_url(request) }}">
    <table id="card_form">
        {% if 'auth_failure' in form.errors %}
        <tr>
            <td>&nbsp;</td>
            <td class="error"><b>{{ form.errors['auth_failure'] }}</b></td>
        </tr>
        {% endif %}
        {% for field in form %}
            {{ with_errors(field) }}
        {% endfor %}
        <tr>
            <td>&nbsp;</td>
            <td class="form_submit">
                <input type="submit" value="Login" />
            </td>
        </tr>
    </table>
    </form>
{% endblock %}
